const api = require('../../utils/api.js');
const app = getApp();

Page({
  onLoad(options) {
    app.pageOnLoad(this);
    let user_info = wx.getStorageSync('user_info');
    this.setData({
      store: wx.getStorageSync('store'),
      user_info,
    });
    wx.showModal({
      title: '提示',
      content: '是否核销？',
      success: function(e) {
        if (e.confirm) {
          wx.showLoading({
            title: '核销中',
          });
          app.ws_micro_shoprequest({
            url: api.user.card_clerk,
            data: {
              user_card_id: decodeURIComponent(options.scene),
            },
            success: function(res) {
              wx.showModal({
                title: '提示',
                content: res.msg,
                showCancel: false,
                success: function(res) {
                  if (res.confirm) {
                    app.util.navigateTo(
                      '/ws_micro_shop/pages/index/index',
                      {},
                      true
                    );
                  }
                },
              });
            },
            complete: function() {
              wx.hideLoading();
            },
          });
        } else if (e.cancel) {
          app.util.navigateTo('/ws_micro_shop/pages/index/index', {}, true);
        }
      },
    });
  },
});
